package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.IVipRecordService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.VipRecordCreateValidate;
import com.mdd.admin.validate.VipRecordUpdateValidate;
import com.mdd.admin.validate.VipRecordSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.VipRecordListedVo;
import com.mdd.admin.vo.VipRecordDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/vipRecord")
@Api(tags = "vip开通记录管理")
public class VipRecordController {

    @Resource
    IVipRecordService iVipRecordService;

    @GetMapping("/list")
    @ApiOperation(value="vip开通记录列表")
    public AjaxResult<PageResult<VipRecordListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated VipRecordSearchValidate searchValidate) {
        PageResult<VipRecordListedVo> list = iVipRecordService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="vip开通记录详情")
    public AjaxResult<VipRecordDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        VipRecordDetailVo detail = iVipRecordService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "vip开通记录新增")
    @PostMapping("/add")
    @ApiOperation(value="vip开通记录新增")
    public AjaxResult<Object> add(@Validated @RequestBody VipRecordCreateValidate createValidate) {
        iVipRecordService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "vip开通记录编辑")
    @PostMapping("/edit")
    @ApiOperation(value="vip开通记录编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody VipRecordUpdateValidate updateValidate) {
        iVipRecordService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "vip开通记录删除")
    @PostMapping("/del")
    @ApiOperation(value="vip开通记录删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iVipRecordService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
